package com.airforcehospital;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Component
public class SessionSchedual {

    //@Scheduled(cron = "0/1 * * * * ?")
    //@PostConstruct
    public void run() throws Exception{
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        List<Future<String>> list = new ArrayList<>();
        for(int i=0;i<3;i++){
            list.add(executorService.submit(new SessionTask()));
        }
        list.forEach(t -> {
            try {
                System.out.println(t.get());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                throw new RuntimeException(e);
            }
        });
    }
}
